package system_smtp_service

import (
	"gitee.com/Luna-CY/Golang-Project-Template/internal/context"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/errors"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/interface/service"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/logger"
	"gitee.com/Luna-CY/Golang-Project-Template/model"
)

func (cls *Smtp) UpdateLog(ctx context.Context, log *model.SystemSmtpLog, fields ...service.SystemSmtpLogField) errors.Error {
	if nil == log {
		logger.SugarLogger(logger.WithRequestId(ctx), logger.WithStack()).Errorf("ISS_TP.S_TP.UL_OG.134747 log is nil")

		return errors.ErrorServerInternalError("ISS_TP.S_TP.UL_OG.154756", "异常的传入参数")
	}

	for _, field := range fields {
		if err := field(log); nil != err {
			return err.Relation(errors.ErrorServerInternalError("ISS_TP.S_TP.UL_OG.202658", "应用选项失败"))
		}
	}

	if err := cls.smtpLog.SaveSystemSmtpLog(ctx, log); nil != err {
		return err.Relation(errors.ErrorServerInternalError("ISS_TP.S_TP.UL_OG.234830", "更新邮件日志失败"))
	}

	return nil
}
